﻿using System.Text;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;

var path = Console.ReadLine()!;
path = path.Replace("\"", "");
var Images = Image.Load<Rgba32>(path);
Images.Mutate(x => x.Resize(0, 200));

Images = ToGray(Images);

const string chars = "#8XOHLTI)i=+;:,. ";
var bmpStr = new StringBuilder();

for (int i = 0; i < Images.Height; i += 2)
{
    for (int j = 0; j < Images.Width; j++)
    {
        var origalColor = Images[j, i];
        int index = (int)((origalColor.R + origalColor.G + origalColor.B) / 768.0 * chars.Length);
        bmpStr.Append(chars[index]);
    }

    bmpStr.AppendLine();
}

Console.WriteLine(bmpStr);
return;

static Image<Rgba32> ToGray(Image<Rgba32> img)
{
    for (var i = 0; i < img.Height; i++)
    {
        for (var j = 0; j < img.Width; j++)
        {
            var color = img[j, i];
            //计算灰度值
            var gray = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
            //修改该像素点的RGB的颜色
            img[j, i] = new Rgba32(gray, gray, gray);
        }
    }

    return img;
}